package com.chenjun.common.util.crypto;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.codec.binary.Hex;

public class SHAUtils {
	//private static String str = "liwei_01";
	//private static String entStr="aa5e6011d50f31814f3247993ff26b93d3474f078acb44c35d80a220fbe69ad9";

	public static String enSHA1(String str) throws NoSuchAlgorithmException {
		MessageDigest instance = MessageDigest.getInstance("SHA");
		instance.update(str.getBytes());
		byte[] digestBytes = instance.digest();
		char[] encodeHex = Hex.encodeHex(digestBytes);
		String enStr = new String(encodeHex);
		return enStr;
	}

	public static String enSHA256(String str) throws NoSuchAlgorithmException {
		MessageDigest instance = MessageDigest.getInstance("SHA-256");
		instance.update(str.getBytes());
		byte[] digestBytes = instance.digest();
		char[] encodeHex = Hex.encodeHex(digestBytes);
		String enStr = new String(encodeHex);
		return enStr;
	}

}
